<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="字段" prop="string2">
        <el-select v-model="queryParams.string2" placeholder="请选择字段" clearable>
          <el-option
            v-for="dict in sys_role_crm_sales"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="字段" style="width: 308px">
        <el-date-picker
          v-model="daterangeDate1"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="Plus"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['crm:report:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="Edit"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['crm:report:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="Delete"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['crm:report:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="Download"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['crm:report:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="reportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="销售" align="center" prop="string1">
        <template #default="scope">
          <dict-tag :options="sys_role_crm_sales" :value="scope.row.string1"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="字段" align="center" prop="string3" />-->
<!--      <el-table-column label="字段" align="center" prop="string4" />-->
<!--      <el-table-column label="字段" align="center" prop="string5" />-->
<!--      <el-table-column label="字段" align="center" prop="string6" />-->
      <el-table-column label="新导入" align="center" prop="long1" />
      <el-table-column label="已电话" align="center" prop="long2" />
      <el-table-column label="已面谈" align="center" prop="long3" />
      <el-table-column label="已复试" align="center" prop="long4" />
      <el-table-column label="已试学" align="center" prop="long5" />
      <el-table-column label="已看协议" align="center" prop="long6" />
      <el-table-column label="已签协议" align="center" prop="long7" />
<!--      <el-table-column label="字段" align="center" prop="date1" width="180">-->
<!--        <template #default="scope">-->
<!--          <span>{{ parseTime(scope.row.date1, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="字段" align="center" prop="date2" width="180">-->
<!--        <template #default="scope">-->
<!--          <span>{{ parseTime(scope.row.date2, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="字段" align="center" prop="date3" width="180">-->
<!--        <template #default="scope">-->
<!--          <span>{{ parseTime(scope.row.date3, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="字段" align="center" prop="date4" width="180">-->
<!--        <template #default="scope">-->
<!--          <span>{{ parseTime(scope.row.date4, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template #default="scope">-->
<!--          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['crm:report:edit']">修改</el-button>-->
<!--          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['crm:report:remove']">删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script setup name="Report">
import { listReport, getReport, delReport, addReport, updateReport } from "@/api/crm/report";

const { proxy } = getCurrentInstance();
const { crm_sales_stage,sys_role_crm_sales } = proxy.useDict('crm_sales_stage','sys_role_crm_sales');

const reportList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const daterangeDate1 = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    report_name: "salesCrmLeadCount"
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询测试列表 */
function getList() {
  loading.value = true;
  queryParams.value.params = {};
  if (null != daterangeDate1 && '' != daterangeDate1) {
    queryParams.value.params["beginDate1"] = daterangeDate1.value[0];
    queryParams.value.params["endDate1"] = daterangeDate1.value[1];
  }
  listReport(queryParams.value).then(response => {
    reportList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    string1: null,
    string2: null,
    string3: null,
    string4: null,
    string5: null,
    string6: null,
    long1: null,
    long2: null,
    long3: null,
    long4: null,
    long5: null,
    date1: null,
    date2: null,
    date3: null,
    date4: null
  };
  proxy.resetForm("reportRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}


/** 重置按钮操作 */
function resetQuery() {
  daterangeDate1.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.string1);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加测试";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _string1 = row.string1 || ids.value
  getReport(_string1).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改测试";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["reportRef"].validate(valid => {
    if (valid) {
      if (form.value.string1 != null) {
        updateReport(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addReport(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _string1s = row.string1 || ids.value;
  proxy.$modal.confirm('是否确认删除测试编号为"' + _string1s + '"的数据项？').then(function() {
    return delReport(_string1s);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('crm/report/export', {
    ...queryParams.value
  }, `report_${new Date().getTime()}.xlsx`)
}

getList();
</script>
